/**
 * Created by xiewl on 2016/12/29.
 */

angular.module('mainApp', [
    'ui.router',
    'mainApp.orderManage',
    'mainApp.survey',
    'mainApp.appointment',
    'mainApp.userManage',
    'mainApp.evaluate',
    'mainApp.doctorManage',
    'mainApp.package',
    'mainApp.knowledge',
    'mainApp.service',
    'mainApp.package',
    'mainApp.member',
    'mainApp.practiceManage',
    'mainApp.channel',
    'mainApp.wecodeCount'
])
.config(function($urlRouterProvider,$compileProvider) {
    $urlRouterProvider.otherwise('/survey/index');
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|leley|mailto|chrome-extension|javascript):/);
})
.directive('errSrc', function() {
    return {
        link: function(scope, element, attrs) {
            element.bind('error', function() {
                if (attrs.src != attrs.errSrc) {
                    attrs.$set('src', attrs.errSrc);
                }
            });
        }
    }
})
.directive('repeatFinish',function(){
    return {
        link: function(scope){
            if(scope.$last){
                //展开二级菜单
               // setTimeout(function () {$('.treeview .menu-item.active').parents('.treeview').addClass('active');},50);
            }
        }
    }
})
/**
 * 权限控制指令
 * 通过指定权限Id可以控制显示与隐藏
 * @author marker
 */
.directive('permission',function(){

    return {
        restrict : 'A',
        template: function(tElement, tAttrs){
            var buttonId = tAttrs.permission;
            $(tElement).hide();
            // window.menuButtons.length;
            if(window.menuButtons){
                angular.forEach(window.menuButtons, function(data){
                    if(buttonId == data.id){
                        $(tElement).show();
                    }
                })
            }
        }
    }
})
.directive('edit',function () {
        return {
            restrict:'AE',
            link:function (scope, elem) {
                var html1 = '<style>input[type=color]{width: 10px;height: 25px;border: 0;padding: 0;background-color: transparent;outline: none;}::-webkit-color-swatch { height:21px; position:relative; left: 0px; top:4px; border: none}</style>'+
                    '<input type="color" > <span style="font-size: 16px;padding-left: 2px">标题</span>'
                KindEditor.plugin('modal1',function () {
                    var editor = this,name = 'modal1';
                    editor.clickToolbar(name,function () {
                        editor.insertHtml(html1);
                    })
                });
                var html3 = '<p style="max-width: 750px;">这里输入内容</p>';
                KindEditor.plugin('modal3',function () {
                    var editor = this,name='modal3';
                    editor.clickToolbar(name,function () {
                        editor.insertHtml(html3)
                    })
                });
                KindEditor.lang({
                    modal1:'标题',
                    modal2:'头像',
                    modal3:'内容'
                });


                window.editor=KindEditor.create(elem,{
                    filterMode : false,
                    resizeType : 0,
                    height: '350px',
                    width:'100%',
                    items : [
                        'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
                        'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                        'anchor', 'link', 'unlink', '|', 'about','modal1','modal2','modal3'
                    ],
                    newlineTag:'br'
                })
            }
        }
    })
.controller('MainController',function ( $rootScope, $scope) {

    /**
     * 注销登录
     */
    $scope.logout = function () {
        delete localStorage.userName;
        delete localStorage.token ;
       delete localStorage.userId ;
        location.href='./login.html';
    }
    //菜单伸缩
    $(".sidebar-menu").on('click','li.treeview',function () {
       // alert(1);
        $(this).addClass('active').siblings('li.treeview').removeClass('active');
        $("li.treeview").not('.active').find('.treeview-menu ').hide();
    })


    //获取二级菜单
     $scope.menuList=[
        {title:'订单管理',iconfont:'fa-folder-o',url:'/orderManage/index'},
        {title:'我的预约',iconfont:'fa-folder-o',child:[{title:'预约名医',iconfont:'fa-folder-o',url:'/appointment/expert_meeting'},{title:'电话咨询',iconfont:'fa-folder-o',url:'/appointment/tel_consultation/1'}]},
        {title:'医生管理',iconfont:'fa-folder-o',url:'/doctorManage/doctorList'},
        {title:'用户管理',iconfont:'fa-folder-o',url:'/userManage/userList'},
        {title:'套餐管理',iconfont:'fa-folder-o',url:'/package/packageList'},
        {title:'知识分类',iconfont:'fa-folder-o',url:'/knowledge/knowledgeList'},
        {title:'评价管理',iconfont:'fa-folder-o',url:'/evaluate/evaluateList'},
        {title:'服务设置',iconfont:'fa-folder-o',url:'/service/serviceList'},
        {title:'会员管理',iconfont:'fa-folder-o',url:'/member/memberList'},
        {title:'执业管理',iconfont:'fa-folder-o',url:'/practiceManage/practiceList'},
        {title:'渠道管理',iconfont:'fa-folder-o',url:'/channel/channelList'},
        {title:'二维码统计',iconfont:'fa-folder-o',url:'/wecodeCount/wecodeList'},

    ]
    $scope.$on('arg', function(event,data) {
        data=parseInt(data)
       $('.sidebar-menu > .treeview').removeClass('active').eq(data-1).addClass('active');
    });



});


var http = HttpRequest.prototype;


// 注销登录
// http.mainLoginout = function (cb) {
//     var opts = {
//         url : baseUrl + '/api/logout.do',
//         type : 'get'
//     };
//     this.baseRequest(cb,opts);
// };